package com.rzy.cqh.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.rzy.cqh.model.Model;

public abstract class BaseServlet extends HttpServlet {
  protected final Logger log = Logger.getLogger(BaseServlet.class);

  @Override
  protected final void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    doGet(req, resp);
  }

  @Override
  protected final void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String uri = req.getRequestURI();
    //log.debug("===== uri:" + uri);

    String path = uri.substring(uri.lastIndexOf("/")+1);
    log.debug("===== path:" + path);
    Model model = new Model(req);

    String forward = doAction(path, model);
    log.debug("===== forward:" + forward);
    req.getRequestDispatcher(forward).forward(req, resp);
  }

  protected abstract String doAction(String path, Model model) throws ServletException, IOException;
}
